import Vue from 'vue'
import Router from 'vue-router'
/* Layout */
import Layout from '@/layout'
import department from '@/router/modules/department.js'
import role from '@/router/modules/role.js'
import employee from '@/router/modules/employee.js'
import permission from '@/router/modules/permission.js'
import attendance from '@/router/modules/attendance.js'
import approval from '@/router/modules/approval.js'
import salary from '@/router/modules/salary.js'
import social from '@/router/modules/social.js'

Vue.use(Router)

// 静态路由
export const constantRoutes = [
  // 登录路由
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  // 404路由
  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  // 一级 - 主页路由
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [
      {
        path: 'dashboard',
        name: 'Dashboard',
        component: () => import('@/views/dashboard/index'),
        meta: { title: '首页', icon: 'dashboard' }
      }
    ]
  }
  // 404 page must be placed at the end !!!
  // { path: '*', redirect: '/404', hidden: true }
]

// 动态路由 - 根据权限进行访问
export const asyncRoutes = [
  // 二级 - 组件架构路由
  department,
  // 二级 - 角色管理路由
  role,
  // 二级 - 员工管理路由
  employee,
  // 二级 - 权限管理路由
  permission,
  // 二级 - 考勤管理路由
  attendance,
  // 二级 - 审批管理路由
  approval,
  // 二级 - 工资管理路由
  salary,
  // 二级 - 社保管理路由
  social
]

// 创建路由实例对象
const createRouter = () => new Router({
  mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  // 重置路由
  router.matcher = newRouter.matcher // reset router
}

// 导出路由实例
export default router
